package com.luo.storage.utils;

import com.luo.storage.model.domain.User;
import org.springframework.stereotype.Component;

@Component
public class UserContext {

    /**
     * 线程独立副本，数据隔离工具
     */
    private static final ThreadLocal<Long> USER_ID_HOLDER = new ThreadLocal<>();

    public static void setUserId(Long userId){
        USER_ID_HOLDER.set(userId);
    }

    public static Long getUserId(){
        return USER_ID_HOLDER.get();
    }

    public static void clear(){
        USER_ID_HOLDER.remove();
    }
}
